<?php
/**
 *
 * @authors  Ysg (y.shi.guo@gmail.com)
 * @website  http://ysg.bonza.cn
 * @date     2017-08-04 09:16:04
 */
$allowtype =['jpg','jpeg','png','gif','bmp'];
$img_mime_type = ['image/jpg','image/gif','image/pjpeg','image/jpeg','image/png','image/x-png'];

$arr = explode('.',$_FILES['file']['name']);
$extension = end($arr);

if ($_FILES['file']['size'] < 200000 && in_array($_FILES['file']['type'],$img_mime_type) && in_array($extension,$allowtype)) {
	if ($_FILES['file']['error'] > 0) {
		echo "文件上传出错，请稍候再试！";
	}else{
		/*echo "上传文件名: " . $_FILES["file"]["name"] . "<br>";
		echo "文件类型: " . $_FILES["file"]["type"] . "<br>";
		echo "文件大小: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
		echo "文件临时存储的位置: " . $_FILES["file"]["tmp_name"];*/
		// print_r($_FILES['file']);
		if (file_exists('upload/'.$_FILES["file"]["name"])) {
			# code...
			echo "文件已经存在";
		}else{
			if (!file_exists('upload') && !is_dir('upload')) {
				mkdir('upload',0777);
			}
			move_uploaded_file($_FILES["file"]["tmp_name"],'upload/'.$_FILES["file"]["name"]);
		}
	}
}else{
	echo "未知文件类型或文件大小不符";
}

